// FqlService.cs
// Facebook/Framework/Service
// Copyright (c) 2007, Nikhil Kothari. All Rights Reserved.
//

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using Facebook.Service.Core;

namespace Facebook.Service {

    /// <summary>
    /// Represents the service APIs that allow executing FQL-based queries.
    /// </summary>
    public sealed class FqlService {

        private FacebookSession _session;

        internal FqlService(FacebookSession session) {
            Debug.Assert(session != null);
            _session = session;
        }

        /// <summary>
        /// Executes the specified FQL-based query.
        /// </summary>
        /// <param name="query">The FQL-based query.</param>
        /// <returns>The result set associated with the query.</returns>
        public object ExecuteQuery(string query) {
            if (String.IsNullOrEmpty(query)) {
                throw new ArgumentNullException("query");
            }

            FacebookRequest request = new FacebookRequest(_session);
            request.Parameters["query"] = query;

            FacebookResponse response = request.InvokeMethod("fql.query");
            if (response.Status == FacebookResponseStatus.Succeeded) {
                return response.Result;
            }

            return null;
        }
    }
}
